package server.handler.friendHandler;

import com.alibaba.fastjson.JSONObject;
import common.EnvelopeMessage;
import common.bodies.FriendShipBody;
import server.dao.FriendDao;
import server.handler.SimpleHandler;
import server.session.Session;

import java.util.List;

public class FriendListHandler implements SimpleHandler {
    @Override
    public void handle(EnvelopeMessage msg, Session session) {
//        System.out.println(session.getClientId());
        JSONObject body = msg.getBody();
        Integer userId = body.getInteger("userId");
        List<FriendShipBody> friends = new FriendDao().getFriendList(userId);
        JSONObject object = new JSONObject();
        object.put("friends",friends);
        EnvelopeMessage back = new EnvelopeMessage("friend","list",object);
        String json = JSONObject.toJSONString(back);
        System.out.println("服务端返回"+json);
        session.send(json);
    }
}
